package aliyun

import (
	openapiutil "github.com/alibabacloud-go/darabonba-openapi/v2/utils"
	dysmsapi20170525 "github.com/alibabacloud-go/dysmsapi-20170525/v5/client"
	credential "github.com/aliyun/credentials-go/credentials"
)

type AliDysmsapiClient AliyunConfig

func NewDysmsapiClient(ak, sk string) *AliDysmsapiClient {
	return &AliDysmsapiClient{
		AccessKeyId:     ak,
		AccessKeySecret: sk,
		Endpoint:        "dysmsapi.aliyuncs.com",
	}
}

func (a *AliDysmsapiClient) CreateClient() (_result *dysmsapi20170525.Client, _err error) {
	credential, _err := credential.NewCredential(nil)
	if _err != nil {
		return _result, _err
	}

	config := &openapiutil.Config{
		AccessKeyId:     &a.AccessKeyId,
		AccessKeySecret: &a.AccessKeySecret,
		Credential:      credential,
		Endpoint:        &a.Endpoint,
	}
	// Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
	_result = &dysmsapi20170525.Client{}
	_result, _err = dysmsapi20170525.NewClient(config)
	return _result, _err
}
